package com.tancire.question.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.question.domain.TrainActivity;
import com.tancire.question.service.ITrainActivityService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 答题活动Controller
 *
 * @author tancire
 * @date 2024-10-10
 */
@RestController
@RequestMapping("/question/trainActivity")
public class TrainActivityController extends BaseController {
    @Resource
    private ITrainActivityService trainActivityService;

    /**
     * 查询答题活动列表
     */
    @PreAuthorize("@ss.hasPermi('question:trainActivity:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainActivity trainActivity) {
        startPage();
        List<TrainActivity> list = trainActivityService.selectTrainActivityList(trainActivity);
        return getDataTable(list);
    }

    /**
     * 导出答题活动列表
     */
    @PreAuthorize("@ss.hasPermi('question:trainActivity:export')")
    @Log(title = "答题活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainActivity trainActivity) {
        List<TrainActivity> list = trainActivityService.selectTrainActivityList(trainActivity);
        ExcelUtil<TrainActivity> util = new ExcelUtil<TrainActivity>(TrainActivity.class);
        util.exportExcel(response, list, "答题活动数据");
    }

    /**
     * 获取答题活动详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:trainActivity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(trainActivityService.selectTrainActivityById(id));
    }

    /**
     * 处理答题结果
     */
    @PreAuthorize("@ss.hasPermi('question:trainActivity:result')")
    @GetMapping(value = "/handle/result/{id}")
    public AjaxResult handleActivityResult(@PathVariable("id") Long id) {
        this.trainActivityService.handleActivityResult(id);
        return AjaxResult.success();
    }

    /**
     * 新增答题活动
     */
    @PreAuthorize("@ss.hasPermi('question:trainActivity:add')")
    @Log(title = "答题活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainActivity trainActivity) {
        return toAjax(trainActivityService.insertTrainActivity(trainActivity));
    }

    /**
     * 修改答题活动
     */
    @PreAuthorize("@ss.hasPermi('question:trainActivity:edit')")
    @Log(title = "答题活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainActivity trainActivity) {
        return toAjax(trainActivityService.updateTrainActivity(trainActivity));
    }

    /**
     * 删除答题活动
     */
    @PreAuthorize("@ss.hasPermi('question:trainActivity:remove')")
    @Log(title = "答题活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(trainActivityService.deleteTrainActivityByIds(ids));
    }
}
